import time
import sys

# 循环读取磁盘用量


def userd(orin, name):
    use_old = 0
    while True:
        time.sleep(2)
        stdin, stdout, stderr = orin.exec_command("sudo df -m |grep /dev/sda1 |awk '{print $2,$3}'")

        if stderr.read().decode("utf-8"):
            # 未找到硬盘
            continue

        disk = stdout.read().decode("utf-8").strip().split(" ")
        size, use_new = disk

        # print("\r" + "%s硬盘用量为：%s" % (name, use_new), end="", flush=True)

        if use_old == 0:
            use_old = int(use_new)
            continue

        if int(use_new) > use_old:
            continue

        elif int(use_new) == use_old:
            print("%s硬盘大小无变化，用量（Used）：%s" % (name, use_new))
